package com.sean.findme.search;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.app.ActivityGroup;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

import com.sean.findme.FmActivityMgrCtrller;
import com.sean.findme.FmDBHelp;
import com.sean.findme.R;
import com.sean.findme.dbentrys.XMLSubwayDetail;
import com.sean.findme.near.NearActivity;

public class SearchSubwayDetailActivity extends Activity{
	
	private HashMap<String, String> premap = null;
	private ArrayList<XMLSubwayDetail> list = null;
	private ListView mListView = null;
	private ActivityGroup group = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.search_subway_detail);
		
		group = (ActivityGroup)getParent();
		premap = FmActivityMgrCtrller.getInstance(null).getCurActivityMgr().getListActivityInfo().peek().getMap();
		
		list = FmDBHelp.getInstance(null, 0).subwayDetailDBEntry.fetchAllRecordsByKeys(premap.get("city_key"), premap.get("subway_key"));
		
		initViews();
		
	}

	private void initViews() {

		mListView = (ListView)findViewById(R.id.search_subway_detail_list);
		ArrayList<String> names = new ArrayList<String>();
		if( list != null )
		{
			for( int i = 0; i < list.size(); i++ )
				names.add(list.get(i).getName());
		}
		
		ArrayAdapter adapter = new ArrayAdapter(SearchSubwayDetailActivity.this, android.R.layout.simple_list_item_1,names);
		mListView.setAdapter(adapter);
		
		mListView.setOnItemClickListener(new OnItemClickListener(){

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int index,
					long arg3) {
				HashMap<String,String> map = new HashMap<String,String>();
				String title = getResources().getString(R.string.search_tab)+"-"+list.get(index).getName();
				map.put("text", premap.get("text"));
				map.put("position", list.get(index).getPosition());
				map.put("title", title);
				map.put("type", "2");
				
				SearchActivityManager.getInstance().JmpActivity(SearchSubwayDetailActivity.this, NearActivity.class, group, map, true);
				
			}
			
		});
		
		
		
	}
	
	

}
